<template>
  <div class="home-module__teacher container">
    <div class="teacher-header">
      <div class="title">{{ datas.title }}</div>
      <div class="more" @click="goMore">更多</div>
    </div>

    <!-- 宫格 -->
    <div v-if="datas.arrange == 1" class="teacher-list gongge" :class="`col-${datas.column}`">
      <div class="item" v-for="(item, index) in datas.list" :key="index">
        <div class="picture" @click="goTeacher(item.user_id)">
          <edu-image class="hvr-grow" :src="item.avatar" fit="cover" lazy></edu-image>
        </div>
        <div class="content">
          <div class="signal">
            <div class="name" @click="goTeacher(item.user_id)">{{ item.title }}</div>
            <div class="grade" v-if="item.level_text">/{{ item.level_text }}</div>
          </div>
          <div class="firmware" v-if="datas.column == 2">{{ item.signature }}</div>
        </div>
      </div>
    </div>

    <!-- 滚动 -->
    <div
      v-else-if="datas.arrange == 2"
      class="teacher-list scroll"
      :class="`teacher-list-swiper-${moduleIndex}`"
    >
      <swiper :options="teacherSwiperOption">
        <swiper-slide v-for="(item, index) in datas.list" :key="index">
          <div class="item">
            <div class="picture" @click="goTeacher(item.user_id)">
              <edu-image class="hvr-grow" :src="item.avatar" fit="cover" lazy></edu-image>
            </div>
            <div class="content">
              <div class="signal">
                <div class="name" @click="goTeacher(item.user_id)">{{ item.title }}</div>
                <div class="grade" v-if="item.level_text">/{{ item.level_text }}</div>
              </div>
            </div>
          </div>
        </swiper-slide>
      </swiper>
      <div class="swiper-button-prev swiper-button-white"></div>
      <div class="swiper-button-next swiper-button-white"></div>
    </div>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
export default {
  name: 'Teacher',
  components: {
    Swiper,
    SwiperSlide
  },
  props: {
    datas: {
      type: Object,
      default: () => {}
    },
    moduleIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      teacherSwiperOption: {
        slidesPerView: 5,
        spaceBetween: 20,
        loop: false,
        loopAdditionalSlides: 0,
        navigation: {
          nextEl: `.teacher-list-swiper-${this.moduleIndex} .swiper-button-next`,
          prevEl: `.teacher-list-swiper-${this.moduleIndex} .swiper-button-prev`
        }
      }
    }
  },
  methods: {
    // 跳转更多
    goMore() {
      this.$router.push({
        path: '/teacher'
      })
    },
    // 跳转讲师
    goTeacher(id) {
      if (id == 0) return
      this.$router.push({
        path: '/user',
        query: {
          id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/hover.scss';
.home-module__teacher {
  margin-bottom: 30px;
  padding: 30px 0;
  background-color: #ffffff;
  .teacher-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    border-left-width: 3px;
    border-left-style: solid;
    @include edu-color-primary(border-left-color);
    .title {
      font-size: 18px;
      font-weight: bold;
      color: #333333;
      line-height: 22px;
    }
    .more {
      font-size: 14px;
      font-weight: 400;
      color: #aeaeae;
      line-height: 16px;
      cursor: pointer;
    }
  }
  .teacher-list {
    padding: 0 15px;
    margin-top: 30px;
    .item {
      .picture {
        cursor: pointer;
        overflow: hidden;
        .el-image {
          width: 100%;
          height: 100%;
        }
      }
      .content {
        .signal {
          display: flex;
          align-items: flex-end;
          .name {
            font-size: 18px;
            color: $text-color-import;
            font-weight: 500;
            line-height: 1;
            cursor: pointer;
            @include ellipsis;
          }
          .grade {
            font-size: 14px;
            font-weight: 500;
            color: $text-color-auxiliary;
            line-height: 1;
            white-space: nowrap;
          }
        }
        .firmware {
          margin-top: 15px;
          font-size: 14px;
          font-weight: 400;
          color: $text-color-auxiliary;
          line-height: 21px;
          @include ellipsisLine(3);
        }
      }
    }
    &.gongge {
      display: grid;
      .item {
        grid-column: span 1 / span 1;
      }
      &.col-2 {
        grid-gap: 28px 60px;
        grid-template-columns: repeat(2, minmax(0px, 1fr));
        .item {
          padding: 10px;
          display: flex;
          background: rgba(48, 49, 51, 0.02);
          border-radius: 6px;
          .picture {
            width: 132px;
            height: 132px;
          }
          .content {
            flex: 1;
            min-width: 0;
            padding-top: 8px;
            margin-left: 20px;
          }
        }
      }
      &.col-3,
      &.col-4 {
        grid-gap: 28px 22px;
        .item {
          .content {
            margin-top: 20px;
            .signal {
              justify-content: center;
            }
          }
        }
      }
      &.col-3 {
        grid-template-columns: repeat(3, minmax(0px, 1fr));
        .item {
          .picture {
            height: 375px;
          }
        }
      }
      &.col-4 {
        grid-template-columns: repeat(4, minmax(0px, 1fr));
        .item {
          .picture {
            height: 276px;
          }
        }
      }
    }
    &.scroll {
      position: relative;
      .swiper-button-prev,
      .swiper-button-next {
        outline: none;
        width: 34px;
        height: 34px;
        top: 106px;
        margin-top: -17px;
        border-radius: 50%;
        color: #ffffff;
        background: rgba(51, 51, 51, 0.1);
        &:after {
          font-size: 16px;
        }
        &:hover {
          @include edu-color-primary;
        }
      }
      .swiper-button-prev.swiper-button-disabled,
      .swiper-button-next.swiper-button-disabled {
        pointer-events: auto;
        &:hover {
          color: #ffffff !important;
        }
      }
      .swiper-button-prev {
        left: 25px;
      }
      .swiper-button-next {
        right: 25px;
      }
      .item {
        .picture {
          height: 218px;
        }
        .content {
          margin-top: 20px;
          .signal {
            justify-content: center;
          }
        }
      }
    }
  }
}
</style>
